package com.sxz.sbs.util;

import android.os.CountDownTimer;
import android.widget.Button;

import com.sxz.sbs.app.AppConstant;


/**
 * 验证码倒计时
 * @author tian
 */

public class VerifyCountDownUtil extends CountDownTimer {
    private Button mButton;

    public VerifyCountDownUtil(Button button) {
        super(AppConstant.Config.MESSAGE_COUNT_DOWN, 1000);//默认
        this.mButton = button;
    }

    public VerifyCountDownUtil(Button button, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);//自定义时长
    }

    @Override
    public void onTick(long millisUntilFinished) {
        mButton.setEnabled(false); //设置不可点击
        mButton.setText("已发送"+"("+millisUntilFinished / 1000 + ")");
    }

    @Override
    public void onFinish() {
        mButton.setText("获取验证码");
        mButton.setEnabled(true);//重新获得点击
        cancel();
    }

    /**
     * 销毁 避免内存泄漏
     */
    public void destroy() {
        cancel();
    }
}
